<?php
class Menu extends Model{

	public function getmenu() {
		$sql = "select * from ".$this->db->prefix."privilegecate where show_nav=1 order by ordernum asc";
		$pcarr = $this->db->getAll($sql);
		foreach($pcarr as $key=>$value){
			$sql = "select * from ".$this->db->prefix."privilege where show_nav=1 and pc_id = '".$value['pc_id']."' order by ordernum asc";
			$pcarr[$key]['parr']=$this->db->getAll($sql);
		}
		return $pcarr;
	}
	public function getdiy() {
		$sql = "select * from ".$this->db->prefix."privilege where show_nav=1 and diy_nav = 1";
		return $this->db->getAll($sql);
	}

	public function savediy() {
		if(isset($_POST['diydb'])){
			$this->helper('number');
			$table = $this->db->prefix.'privilege';

			$table = $this->db->prefix.'privilege';
			$wherestr = 'diy_nav=1';
			$arr = array('diy_nav'=>0
			);
			$this->db->update($table, $arr,$wherestr);

			$wherestr = 'p_id in ('.range_format($_POST['diydb']).')';
			$arr = array('diy_nav'=>1
			);
			$this->db->update($table, $arr,$wherestr);
		}else{
			$table = $this->db->prefix.'privilege';
			$wherestr = 'diy_nav=1';
			$arr = array('diy_nav'=>0
			);
			$this->db->update($table, $arr,$wherestr);
		}
	}
}